/*
 * 爱组搭，低代码组件化开发平台
 * ------------------------------------------
 * 受知识产权保护，请勿删除版权申明，开发平台不允许做非法网站，后果自负
 */
package com.aizuda.boot.modules.system.mapper;

import com.aizuda.boot.modules.system.entity.SysDepartment;
import com.aizuda.boot.modules.system.entity.SysUserDepartment;
import com.aizuda.service.mapper.CrudMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 系统用户部门 Mapper 接口
 * </p>
 *
 * @author 青苗
 * @since 2023-10-08
 */
public interface SysUserDepartmentMapper extends CrudMapper<SysUserDepartment> {

    /**
     * 根据用户id和飞书租户Key获取部门信息
     *
     * @param userId
     * @param tenantKey
     * @return com.aizuda.boot.modules.system.entity.SysDepartment
     * @author hjw
     * @date 2025/7/12 14:09
     */
    @Select("select sys_department.* from sys_department left join sys_user_department on sys_user_department.department_id = sys_department.id where sys_user_department.user_id = #{userId} and sys_department.tenant_key = #{tenantKey} limit 1")
    SysDepartment getDepByUserIdAndTenantKey(@Param("userId") Long userId, @Param("tenantKey") String tenantKey);
}
